package com.yuandian.business.monitor.documentExport;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CustomRequestInterceptor implements RequestInterceptor {

	@Autowired
	private LoadBalancerClient loadBalancerClient;

	@Override
	public void apply(RequestTemplate template) {
		ServiceInstance serviceInstance = loadBalancerClient.choose("bpm-management");
		if (serviceInstance != null) {
			String serviceIpAddress = serviceInstance.getHost();
			int servicePort = serviceInstance.getPort();
			String serviceUrl = "http://" + serviceIpAddress + ":" + servicePort + template.url();
			log.info("request url is : {}", serviceUrl);
		}

	}
}
